package com.hbyj.struts.action;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import javax.servlet.http.HttpServletRequest;

import net.sf.json.JSONObject;

import org.apache.struts2.ServletActionContext;

import com.hbyj.db.function.DbTools;
import com.hbyj.hbm.vo.Jbqk01;
import com.hbyj.hbm.vo.M_set;
import com.hbyj.hbm.vo.YjdcYjdc01;
import com.hbyj.util.ChangeTool;
import com.hbyj.util.Constants;
import com.hbyj.util.PageClass;
import com.opensymphony.xwork2.ActionSupport;

public class XtzhAction extends ActionSupport{
	private String jsonResult;
	private int total;
	private List rows = new ArrayList();
	
	public String getJsonResult() {
		return jsonResult;
	}

	public void setJsonResult(String jsonResult) {
		this.jsonResult = jsonResult;
	}

	public int getTotal() {
		return total;
	}

	public void setTotal(int total) {
		this.total = total;
	}

	public List getRows() {
		return rows;
	}

	public void setRows(List rows) {
		this.rows = rows;
	}
	
	public String queryYjdcry(){
		HttpServletRequest request = ServletActionContext.getRequest();
		String pageNo = request.getParameter("page");
		String tybh = request.getParameter("tybh");
		String zhlx = request.getParameter("zhlx");
		int pageSize = Constants.PAGE_KEY;
		String hql = "from YjdcYjdc01 where yjdc01000 like '"+tybh+"'";
		String countHql = "select count(*) from YjdcYjdc01 where yjdc01000 like '"+tybh+"'";
		if(!zhlx.equals("")){
			hql = hql +" and yjdc01020 = '"+zhlx+"'";
			countHql = countHql + " and YJDC01020 = '"+zhlx+"'";
		}
		total = DbTools.getDataHQLCount(countHql);
		PageClass page = new PageClass();
		page.setPageShow(pageSize);  //设置每页显示的行数
		page.setPageCount(total);  //设置总页数
		page.setCurrentPage(Integer.parseInt(pageNo));  //设置当前页
		int first=page.getNextIndex(); //获得开始的索引值
		int max=page.getPageShow();  //获得每次显示的值
		List<YjdcYjdc01> temp = (List)DbTools.findPageHQL(first, max,hql);
		List result = new ArrayList();
		for(int i =0;i<temp.size();i++){
			YjdcYjdc01 yjdc01 = temp.get(i);
			String zhtybh = yjdc01.getYjdc01000();
			String jbqkHql = "from Jbqk01 where jbqk0100 = '"+zhtybh+"' and jbqk0102 = '3'";
			List listJb = DbTools.findByHql(jbqkHql);
			Jbqk01 jb = new Jbqk01();;
			if(listJb.size()>0){
				jb = (Jbqk01)DbTools.findByHql(jbqkHql).get(0);
				//灾害名称、灾害类型、地理位置、调查人、调查单位、调查时间
				String yjdcryZhmc = jb.getJbqk0110();
				String yjdcryZhlx = yjdc01.getYjdc01020();
				String yjdcryDlwz = yjdc01.getYjdc01030();
				String yjdcryDcr = yjdc01.getYjdc01250();
				String yjdcryDcdw = yjdc01.getYjdc01260();
				Date yjdcryDcsj = yjdc01.getYjdc01270();
				Yjdcry ry = new Yjdcry(yjdcryZhmc, yjdcryZhlx, yjdcryDlwz, yjdcryDcr, yjdcryDcdw, yjdcryDcsj);
				result.add(ry);
			}
		}
		total = result.size();
		rows = result;
		return SUCCESS;
	}
	
	
	public String queryJcjg(){
		HttpServletRequest request = ServletActionContext.getRequest();
		String pageNo = request.getParameter("page");
		String tybh = request.getParameter("tybh");
		int pageSize = Constants.PAGE_KEY;
		String hql = "from ZyqcJcba01a where jcba01a015 like '"+tybh+"'";
		String countHql = "select count(*) from ZyqcJcba01a where jcba01a015 like '"+tybh+"'";
		total = DbTools.getDataHQLCount(countHql);
		PageClass page = new PageClass();
		page.setPageShow(pageSize);  //设置每页显示的行数
		page.setPageCount(total);  //设置总页数
		page.setCurrentPage(Integer.parseInt(pageNo));  //设置当前页
		int first=page.getNextIndex(); //获得开始的索引值
		int max=page.getPageShow();  //获得每次显示的值
		rows = (List)DbTools.findPageHQL(first, max,hql);
		return SUCCESS;
	}
	
	
	public String queryYjdw(){
		HttpServletRequest request = ServletActionContext.getRequest();
		String pageNo = request.getParameter("page");
		String xzbh = request.getParameter("xzbh");
		int pageSize = Constants.PAGE_KEY;
		String hql = "from YjczYjcz03 where yjcz03000 like '"+xzbh+"'";
		String countHql = "select count(*) from YjczYjcz03 where yjcz03000 like '"+xzbh+"'";
		total = DbTools.getDataHQLCount(countHql);
		PageClass page = new PageClass();
		page.setPageShow(pageSize);  //设置每页显示的行数
		page.setPageCount(total);  //设置总页数
		page.setCurrentPage(Integer.parseInt(pageNo));  //设置当前页
		int first=page.getNextIndex(); //获得开始的索引值
		int max=page.getPageShow();  //获得每次显示的值
		rows = (List)DbTools.findPageHQL(first, max,hql);
		return SUCCESS;
	}
	
	public String queryZjk(){
		HttpServletRequest request = ServletActionContext.getRequest();
		String pageNo = request.getParameter("page");
		String xzbh = request.getParameter("xzbh");
		int pageSize = Constants.PAGE_KEY;
		String hql = "from YjczYjcz06,YjczYjcz13 where yjcz06010 =yjcz13055 and yjcz13000 like '"+xzbh+"'";
		String countHql = "select count(*) from YjczYjcz06,YjczYjcz13 where yjcz06010 =yjcz13055  and yjcz13000 like '"+xzbh+"'";
		total = DbTools.getDataHQLCount(countHql);
		PageClass page = new PageClass();
		page.setPageShow(pageSize);  //设置每页显示的行数
		page.setPageCount(total);  //设置总页数
		page.setCurrentPage(Integer.parseInt(pageNo));  //设置当前页
		int first=page.getNextIndex(); //获得开始的索引值
		int max=page.getPageShow();  //获得每次显示的值
		rows = (List)DbTools.findPageHQL(first, max,hql);
		return SUCCESS;
	}
	
}
